package com.lagou.server;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @author yangpeng
 * @time 2020/5/21
 * @since 1.0.0
 */
public class ZkProxy {

    /* IP地址*/
    public static final String IP = "127.0.0.1";

    /*端口号*/
    public static final Integer PORT = 8991;

    /*当前服务在zk上的节点名称*/
    public static final String ZK_NODE_PATH = "/127.0.0.1:8991";

    private static CuratorFramework client;

    static {
        //创建重试策略
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
        //启动与zk的连接
        client = CuratorFrameworkFactory.builder()
                .connectString("127.0.0.1:2181")
                .sessionTimeoutMs(5000)
                .connectionTimeoutMs(3000)
                .retryPolicy(retryPolicy)
                .namespace("cluster")
                .build();
        client.start();
    }

    public static CuratorFramework getClient() {
        return client;
    }

}
